<script setup lang="ts">
// 获取屏幕边界到安全区域距离
const scanBuy = () => {
  uni.scanCode({
    onlyFromCamera: false,
    scanType: ['qrCode', 'barCode'],
    success: ({ result, scanType, charSet, path }) => {
      console.log('result', result)
    },
    fail: (error) => {

    }
  })
}
</script>
<template>
  <view class="navbar" :style="{ paddingTop: $safeArea.top + 10 + 'px' }">
    <!-- logo文字 -->
    <view class="logo">
      <text class="logo-text">高效 · 亲民 · 快捷</text>
      <view class="scan-container">
        <uni-icons type="scan" size="18"></uni-icons>
        <text class="scan-text" @tap="scanBuy">扫码购</text>
      </view>
    </view>
    <!-- 搜索条 -->
    <navigator url="/pages/user/search" open-type="navigate" hover-class="navigator-hover" class="search">
      <text class="icon-search">商品名称 / 规格 / 编号 / 首字母 / 69码</text>
      <text class="iconfont icon-scan"></text>
    </navigator>
  </view>
</template>

<style lang="scss">
/* 自定义导航条 */
.navbar {
  background-image: url(@/static/images/navigator_bg.png);
  background-size: cover;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-top: 20px;

  .logo {
    display: flex;
    align-items: center;
    height: 64rpx;
    padding-left: 30rpx;

    .logo-image {
      width: 166rpx;
      height: 39rpx;
    }

    .logo-text {
      line-height: 28rpx;
      color: #fff;
      padding-left: 20rpx;
      font-size: 26rpx;
    }

    .scan-container {
      display: flex;
      background-color: #fff;
      padding: 12rpx 24rpx;
      border-radius: 28rpx;
      margin-left: 52rpx;
      align-items: center;

      .scan-text {
        color: #000;
        font-size: 26rpx;
        font-weight: 400;
        padding-left: 12rpx;
      }
    }
  }

  .search {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10rpx 0 26rpx;
    height: 64rpx;
    margin: 16rpx 20rpx;
    color: #fff;
    font-size: 26rpx;
    border-radius: 32rpx;
    background-color: rgba(255, 255, 255, 0.5);
  }

  .icon-search {
    &::before {
      margin-right: 10rpx;
    }
  }

  .icon-scan {
    font-size: 40rpx;
    padding: 15rpx;
  }
}
</style>
